/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2019
 */

package net.dreamlu.db.manager;

import java.util.List;
import java.util.Optional;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import net.dreamlu.db.po.*;
import net.dreamlu.db.qo.*;
import net.dreamlu.db.repo.*;
/**
 *
 * @author lambert.wang email:lambert.wang(a)crediteyes.com
 * @version 1.0
 * @since 1.0
 */
@Service
@Transactional
public class SysDictManager {

	@Autowired
	private SysDictRepository sysDictRepository;

	public List<SysDict> queryAll() {
		return sysDictRepository.findAll();
	}

	/**
	 * 分页查询所有SysDict对象
	 * 
	 * @param pageable pageable  Pageable pageable = PageRequest.of(page, size,sort);
	 * @return
	 */
	public Page<SysDict> querySysDictByPage(Pageable pageable) {
		return sysDictRepository.findAll(pageable);
	}

	/**
	 * 根据条件分页查询SysDict对象
	 * 
	 * @param pageable
	 * @param query
	 * @return
	 */
	public Page<SysDict> querySysDictByPage(Pageable pageable, SysDictQuery sysDictQuery) {
		Specification<SysDict> example = sysDictQuery.createSpecification();
		return sysDictRepository.findAll(example, pageable);
	}

	/**
	 * 不分页查询所有SysDict对象 不分页不带排序
	 * 
	 * @param query
	 * @return
	 */
	public List<SysDict> querySysDict(SysDictQuery sysDictQuery) {
		Specification<SysDict> example = sysDictQuery.createSpecification();
		return sysDictRepository.findAll(example);
	}

	/**
	 * 不分页查询单个SysDict对象 不分页不带排序
	 * 
	 * @param query
	 * @return
	 */
	public SysDict queryUniqueSysDict(SysDictQuery sysDictQuery) {
		Specification<SysDict> example = sysDictQuery.createSpecification();
		Optional<SysDict> op = sysDictRepository.findOne(example);
		if (op.isPresent()) {
			return op.get();
		}
		return null;
	}

	/**
	 * 根据ID查询SysDict对象
	 * 
	 * @param id
	 * @return
	 */
	public SysDict querySysDictById(java.lang.Integer id) {
		Optional<SysDict> op = sysDictRepository.findById(id);
		if (op.isPresent()) {
			return op.get();
		}
		return null;
	}

	/**
	 * 保存SysDict对象
	 * 
	 * @param entity
	 */
	public void saveSysDict(SysDict sysDict) {
		sysDictRepository.save(sysDict);
	}

	/**
	 * 保存多个SysDict对象
	 * 
	 * @param entitys
	 */
	public void saveSysDict(List<SysDict> sysDicts) {
		sysDictRepository.saveAll(sysDicts);
	}

	/**
	 * 批量删除
	 * 
	 * @param deleteList
	 */
	public void deleteSysDict(List<SysDict> deleteList) {
		sysDictRepository.deleteAll(deleteList);
	}

	/**
	 * 批量删除根据查询条件
	 * 
	 * @param query
	 */
	public void deleteSysDict(SysDictQuery sysDictQuery) {
		sysDictRepository.deleteInBatch(querySysDict(sysDictQuery));
	}

	/**
	 * 批量删除根据id
	 * 
	 * @param ids
	 */
	public void deleteSysDictByIds(java.lang.Integer... ids) {
		for (java.lang.Integer id : ids) {
			sysDictRepository.deleteById(id);
		}
	}

	/**
	 * 删除单个对象
	 * 
	 * @param entity
	 */
	public void deleteSysDict(SysDict sysDict) {
		sysDictRepository.delete(sysDict);
	}
}
